/*******************************************************************************
 * Copyright (c) 2007 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.listener;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.gef.EditPart;

import com.cea.papyrus.core.editpart.IUMLObjectEditPart;

/**
 * 
 * 
 * @author Patrick Tessier
 * @since 5 sept. 07
 * this class is used to create a listener on resource and to call automatically editPart.refresh
 * when the resource element is modified
 */

public class ObjectListener implements Adapter {

	/**
	 * the lement that raise the listener
	 */
	private Notifier _target;
	/**
	 * the editpart
	 */
	protected EditPart editPart;
	/** the channel**/
	private static final int channel = 300;


	/**
	 * this class create a listener on the umlElement.
	 * 
	 * @param editPart the editpart of the resource
	 */
	public ObjectListener(IUMLObjectEditPart editPart){
		this.editPart=(EditPart)editPart;
	}

	/**
	 * {@inheritDoc}
	 */
	public void notifyChanged(Notification notification) {
		if (notification.getEventType() != Notification.REMOVING_ADAPTER) {
			editPart.refresh();	
		}
	}

	/**
	 * {@inheritDoc}
	 * */
	public Notifier getTarget() {
		return this._target;
	}

	/**
	 * {@inheritDoc}
	 */
	public void setTarget(Notifier newTarget) {
		this._target = newTarget;
	}

	/**
	 * {@inheritDoc} 
	 */
	public boolean isAdapterForType(Object type) {
		return type.equals(editPart.getModel().getClass());
	}

}